package com.example.demo;


import com.example.demo.controller.FileConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;

import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.NetworkInterface;
import java.util.Enumeration;

@SpringBootApplication
@Controller
public class DemoApplication {



    //局域网手机作业
    public static void main(String[] args) throws UnknownHostException {
        try {
            /*
            * 创建文件路径
            * */
            //创建下载文件夹temp
            File tempFile = new File(FileConfig.downloadPath);
            if (!tempFile.exists()) {
                tempFile.mkdirs();
            }
            //创建收集文件夹upload
            File uploadFile = new File(FileConfig.uploadpath);
            if (!uploadFile.exists()) {
                uploadFile.mkdirs();
            }
            /*
            * 获取主机以太网ip地址
            * */
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface networkInterface = networkInterfaces.nextElement();
                Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    InetAddress inetAddress = inetAddresses.nextElement();
                    /*只选择IPv4地址*/
                    if (inetAddress.isSiteLocalAddress() && !inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().indexOf(":") == -1) {
                        System.out.println("\n地址：" + inetAddress.getHostAddress() + ":1234");
                    }
                }
            }
            /*
            * run springboot class
            * */
            SpringApplication.run(DemoApplication.class, args);
        }catch (Exception e){
            e.printStackTrace();
        }

    }




}
